package com.schoolcloud.share.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.schoolcloud.common.model.PageDTO;
import com.schoolcloud.common.util.UserContext;
import com.schoolcloud.share.dto.SectionVideoRelatedDTO;
import com.schoolcloud.share.entity.SectionVideos;
import com.schoolcloud.share.entity.SetSections;
import com.schoolcloud.share.entity.Videos;
import com.schoolcloud.share.query.SetSectionQuery;
import com.schoolcloud.share.service.SectionVideosService;
import com.schoolcloud.share.mapper.SectionVideosMapper;
import com.schoolcloud.share.service.SetSectionsService;
import com.schoolcloud.share.service.VideosService;
import com.schoolcloud.share.vo.SectionVideoItem;
import com.schoolcloud.share.vo.SectionVideoVO;
import com.schoolcolud.daomybatisplus.dto.MpPageUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author hongmizfb
 * @description 针对表【section_videos(章节视频关联表)】的数据库操作Service实现
 * @createDate 2025-05-16 18:35:15
 */
@Service
@RequiredArgsConstructor
public class SectionVideosServiceImpl extends ServiceImpl<SectionVideosMapper, SectionVideos>
        implements SectionVideosService {


    @Override
    public void createSectionVideoRelation(SectionVideoRelatedDTO relations) {
        List<SectionVideos> collect = relations.getVideoIds().stream().map(item -> {
            SectionVideos sectionVideos = new SectionVideos();
            sectionVideos.setSectionId(relations.getSectionId());
            sectionVideos.setVideoId(item);
            sectionVideos.setAddedBy(UserContext.getUserToInteger());
            sectionVideos.setCreateTime(LocalDateTime.now());
            return sectionVideos;
        }).collect(Collectors.toList());
        saveBatch(collect);
    }

    @Override
    public SectionVideos getByVideoId(Integer id) {
        return lambdaQuery().eq(SectionVideos::getVideoId, id).one();
    }


}




